package com.zsyh.jiujiu.home;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ActivityUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.zyh.toolslib.base.BaseActivity;
import com.example.zyh.toolslib.widget.TitleBar;
import com.google.gson.Gson;
import com.lwb.retrofit.RetrofitTask;
import com.zsyh.jiujiu.Api;
import com.zsyh.jiujiu.R;
import com.zsyh.jiujiu.bean.MessageOrderBean;
import com.zsyh.jiujiu.bean.ZhinanBean;
import com.zsyh.jiujiu.net.MyObserver;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * @ProjectName: livvehelp
 * @Package: com.zsyh.lsb.ui
 * @ClassName:
 * @Description: java类作用描述
 * @Author: zsyh
 * @CreateDate: 2020/9/7 11:59
 * @UpdateUser: liangwanbo
 * @UpdateDate: 2020/9/7 11:59
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class ZhiNanActivity extends BaseActivity {

    @BindView(R.id.title_bar)
    TitleBar titleBar;
    @BindView(R.id.rvlist)
    RecyclerView rvlist;

    private BaseQuickAdapter<ZhinanBean.DataBean, BaseViewHolder> mAdapter;
    List<ZhinanBean.DataBean> list = new ArrayList<>();

    @Override
    protected int initLayout() {
        return R.layout.activittty_zhinan;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        mAdapter=new BaseQuickAdapter<ZhinanBean.DataBean, BaseViewHolder>(R.layout.item_zhinan,list) {
            @Override
            protected void convert(@NonNull BaseViewHolder helper, ZhinanBean.DataBean item) {
                helper.setText(R.id.name,item.getName());
                helper.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Bundle guanli = new Bundle();
                        guanli.putString("name", item.getName());
                        guanli.putString("videourl", item.getVideo());
                        ActivityUtils.startActivity(guanli,VideoActivitty.class);
                    }
                });
            }
        };
        rvlist.setLayoutManager(new LinearLayoutManager(thisActivity));
        rvlist.setAdapter(mAdapter);
        zhinan();
    }

    @Override
    protected void initEvent() {
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    /**
     * 指南
     */
    public void zhinan(){
        RetrofitTask.getInstance()
                .createApi(Api.class)
                .getOperation()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new MyObserver(this,false) {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(String JsonStr) {
                        Log.e("zhinan",JsonStr+"");
                        Gson gson=new Gson();
                        ZhinanBean zhinanBean=gson.fromJson(JsonStr,ZhinanBean.class);
                        if(list!=null){
                            list.clear();
                        }
                        for(int i=0;i<zhinanBean.getData().size();i++){
                            list.add(zhinanBean.getData().get(i));
                        }
                        mAdapter.notifyDataSetChanged();

                    }
                });
    }




}
